#include <iostream>
#include <cstdlib>

int main ()
{
    //堆上内存的管理
    //自行计算所需内存大小  返回指针不需要强转  不需要判断返回值为空
    int *a = new int; 
    //如果申请失败，抛出异常   默认终止程序
    //int *a1 = (int*)malloc(sizeof(int));
    *a= 10;
    std::cout<<*a<<std::endl;
    delete a; //释放内存

    int *a = new int [10]; //申请10个int大小的内存
    for (int i=0;i<10;i++)
    {
        a[i]=i+1;
        std::cout<<a[i]<<std::endl;
    }
    delete []a;//释放数组

//申请二维数组
    int **a = new int* [2];
    for (int i=0;i<2;i++)
    {
        a[i]=new int [3];
    }
    for (int i=0;i<2;i++)
    {
        for (int j=0;j<3;j++)
        {
            std::cout<<a[i][j]=" ";
        }
        std::cout<<std::endl;
    }

    for (int i=0;i<2;i++) delete []a[i];//释放数组
    return 0;
}